package server;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;


public class Logon {
	static Properties agents = new Properties();
	static Properties managers = new Properties();
	static {
		try {
			agents.load(new FileReader("./res/agents.user.properties"));
			managers.load(new FileReader("./res/managers.user.properties"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	static public String logon(String username, String remixPass, String openKey) {
		try {
			if (agents.containsKey(username)) {
				String encode = GlobalConfig.shaHash(agents.get(username));
				if (remixPass.equals(encode))
					return "agent";
				else
					return "fail";
			} else if (managers.containsKey(username)) {
				String encode = GlobalConfig.shaHash(managers.get(username));
				if (remixPass.equals(encode))
					return "manager";
				else
					return "fail";
			}
		} catch (Exception e) {
			return "fail";
		}
		return "fail";
	}
}
